import { createIcon } from '@/utils/icon'
import { ProSchema } from '@ant-design/pro-components'
import service from './service'
import { Button, Select, Modal } from 'antd'
import { IconPicker } from '@/ui'
import { useState } from 'react'

export default [
  {
    title: '父菜单',
    dataIndex: 'parentId',
    valueType: 'treeSelect',
    request: service.list,
  },
  {
    title: '菜单名称',
    dataIndex: 'menuName',
    valueType: 'text',
  },
  {
    title: '菜单图标',
    dataIndex: 'icon',
    hideInSearch: true,
    render: (text: string) => createIcon(text),
    renderFormItem: (schema, config, form) => {
      const [pickerVisible, setPickVisible] = useState<boolean>(false)
      return (
        <div>
          <Button
            style={{ marginRight: '20px' }}
            onClick={() => setPickVisible(true)}
          >
            选择
          </Button>
          {createIcon(form.getFieldValue('icon'))}
          <Modal
            width={1200}
            visible={pickerVisible}
            onCancel={() => {
              setPickVisible(false)
            }}
            footer={null}
          >
            <IconPicker
              onSelect={(name: string) => {
                form.setFieldsValue({ icon: name })
                setPickVisible(false)
              }}
            />
          </Modal>
        </div>
      )
    },
  },
  {
    title: '显示顺序',
    dataIndex: 'orderNum',
    valueType: 'text',
    hideInSearch: true,
    initialValue: '0',
  },
  {
    title: '权限标识',
    dataIndex: 'perms',
    valueType: 'text',
  },
  {
    title: '路由地址',
    dataIndex: 'path',
    valueType: 'text',
    hideInSearch: true,
  },
  {
    title: '权限标识',
    dataIndex: 'perms',
  },
  {
    title: '组件路径',
    dataIndex: 'component',
  },
  {
    title: '路由参数',
    dataIndex: 'params',
  },
  {
    title: '是否缓存',
    dataIndex: 'isCache',
    valueType: 'radio',
    valueEnum: {
      '0': '缓存',
      '1': '不缓存',
    },
    initialValue: '0',
  },
  {
    title: '是否为外链',
    dataIndex: 'isFrame',
    valueType: 'radio',
    valueEnum: {
      '0': '是',
      '1': '否',
    },
    initialValue: '1',
  },
  {
    title: '可见状态',
    dataIndex: 'visible',
    valueType: 'radio',
    valueEnum: {
      '0': '显示',
      '1': '隐藏',
    },
    initialValue: '0',
  },
  {
    title: '组件路径',
    dataIndex: 'component',
    valueType: 'text',
    hideInSearch: true,
  },
  {
    title: '菜单类型',
    dataIndex: 'menuType',
    valueType: 'radio',
    valueEnum: {
      M: '目录',
      C: '菜单',
      F: '按钮',
    },
    hideInTable: true,
  },
  {
    title: '菜单状态',
    dataIndex: 'status',
    valueType: 'radio',
    valueEnum: {
      '0': '启用',
      '1': '停用',
    },
    initialValue: '0',
  },
] as ProSchema[]
